using System;
using System.Collections.Generic;
using System.Net.Http;
using WxLib.Utility;

namespace WxLib
{
    public class WxServer
    {
        private IWxMessageProcessor messageProcessor = null;
        private RequestBuilder requestBuilder = null;
        private HttpClient httpClient = null;
        private IDictionary<string,string> requestParams = null;
        public WxServer()
        {
            messageProcessor = new DefaultMessageProcessor();
        }

        public WxServer(IWxMessageProcessor processor)
        {
            messageProcessor = processor;
        }

        public async string Init()
        {
            requestBuilder = new RequestBuilder();
            httpClient = HttpClientUtility.HttpClientInstance;
            requestParams = new Dictionary<string,string>();

            requestBuilder.Host = "https://login.wx.qq.com/jslogin";
            requestParams.Add("appid","wx782c26e4c19acffb");
            requestParams.Add("redirect_uri","https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage");
            requestParams.Add("fun","new");
            requestParams.Add("lang","zh_CN");
            requestParams.Add("_",GetTimestamp());

            string loginResponse = await httpClient.GetStringAsync(requestBuilder.GetUrl());
        }

        private string GetTimestamp()
        {
            TimeSpan tsStamp = DateTime.Now.ToUniversalTime() - (new DateTime(1970,1,1,0,0,0,0));
            return tsStamp.TotalMilliseconds.ToString();
        }
    }
}